package com.ucar.common.utils.page.jpa.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Range;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;

import io.swagger.annotations.ApiModelProperty;

/**
 * 分页的条件
 * @author dinghao
 *
 */
public class PagingConditions implements Serializable {
	private static final long serialVersionUID = -8859054476799842586L;

	@ApiModelProperty(value = "当前页")
	@Max(value = 9999999)
	@Min(value = 0)
	private int pageIndex = 0;

	@ApiModelProperty(value = "每页条数")
	@Range(min = 1, max = 999999)
	private int pageSize = 10;

	@ApiModelProperty(value = "排序集合")
	@Valid
	private List<OrderingConditions> sort = new ArrayList<>();

	public int getPageIndex() {
		return this.pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public int getPageSize() {
		return this.pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public List<OrderingConditions> getSort() {
		return sort;
	}

	public void setSort(List<OrderingConditions> sort) {
		this.sort = sort;
	}

//	public Sort getSpringBootDataJpaSort() {
//		List<Order> orders = new ArrayList<>();
//		for (OrderingConditions ordering : sort) {
//			if (StringUtils.isNotEmpty(ordering.getDirection()) && StringUtils.isNotEmpty(ordering.getField())) {
//				orders.add(new Order(Direction.fromString(ordering.getDirection()), ordering.getField()));
//			}
//		}
//		return new Sort(orders);
//	}
}
